//
//  mainTabBarViewController.swift
//  纯代码初始化项目
//
//  Created by 白鹭 on 2017/8/9.
//  Copyright © 2017年 com.bailun91. All rights reserved.
//

import UIKit

class mainTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        tabBar.tintColor = UIColor.orange
        
        addChildViewController(HomeViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(MessageViewController() , title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileViewController(), title: "我", imageName: "tabbar_profile")
        
        
    }
    
    
    fileprivate func addChildViewController(_ childController: UIViewController, title:String,imageName:String  ) {
        
        childController.view.backgroundColor = UIColor.randomColor
        childController.title = title
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")
        
        
        //为每一个控制器包装一个导航控制器
        let nav = UINavigationController(rootViewController: childController)
        addChildViewController(nav)
        
    }
    
    
}


extension UIColor {
    //返回随机颜色
    class var randomColor:UIColor{
        get
        {
            let red = CGFloat(arc4random()%256)/255.0
            let green = CGFloat(arc4random()%256)/255.0
            let blue = CGFloat(arc4random()%256)/255.0
            return UIColor(red: red, green: green, blue: blue, alpha: 1.0)
        }
    }
}
